#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Q1mi"
# Date: 2018/11/12

# !/usr/bin/python
# -*-coding:utf-8-*-
# 调用和风天气API查询当前天气信息
# 2017/07/12

import json
import urllib.request
import os


# 在和风天气注册后获得的key
key = '4c0fd8b9171a411a8cb766b2cb23e29f '


# 获取当前地区未来7天的天气信息
def get_json(city):

    url = 'https://free-api.heweather.com/s6/weather/forecast?lang=en&location=' + city + '&key=' + key
    #    print url
    html = urllib.request.urlopen(url).read()
    html_json = json.loads(html)
    weater = html_json['HeWeather6'][0]['daily_forecast']

    return weater

def air_now_weater(city):
    url = 'https://free-api.heweather.com/s6/air/now?lang=en&location=' + city + '&key=' + key
    html = urllib.request.urlopen(url).read()
    html_json = json.loads(html)

    if html_json['HeWeather6'][0]['status'] == 'permission denied':
        return False
    else:
        air = html_json['HeWeather6'][0]['air_now_city']

        return air

if __name__ == '__main__':
    city= 'minhou'
    air = air_now_weater(city)
    print(air)